package com.ruoyi.web.controller.pc;

import com.ruoyi.business.domain.WmsCargo;
import com.ruoyi.business.service.IWmsCargoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 货物信息Controller
 *
 * @author ruoyi
 * @date 2023-12-24
 */
@RestController
@RequestMapping("/business/cargo")
public class WmsCargoController extends BaseController
{
    @Autowired
    private IWmsCargoService wmsCargoService;

    /**
     * 查询货物信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WmsCargo wmsCargo)
    {
        startPage();
        List<WmsCargo> list = wmsCargoService.selectWmsCargoList(wmsCargo);
        return getDataTable(list);
    }

    @GetMapping("/query")
    public AjaxResult query(WmsCargo wmsCargo)
    {
        List<WmsCargo> list = wmsCargoService.selectWmsCargoList(wmsCargo);
        return AjaxResult.success(list);
    }

    /**
     * 导出货物信息列表
     */
    @Log(title = "货物信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WmsCargo wmsCargo)
    {
        List<WmsCargo> list = wmsCargoService.selectWmsCargoList(wmsCargo);
        ExcelUtil<WmsCargo> util = new ExcelUtil<WmsCargo>(WmsCargo.class);
        return util.exportExcel(list, "货物信息数据");
    }

    /**
     * 获取货物信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wmsCargoService.selectWmsCargoById(id));
    }

    /**
     * 新增货物信息
     */
    @Log(title = "货物信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsCargo wmsCargo)
    {
        wmsCargo.setCreateBy(getUsername());
        return toAjax(wmsCargoService.insertWmsCargo(wmsCargo));
    }

    /**
     * 修改货物信息
     */
    @Log(title = "货物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsCargo wmsCargo)
    {
        wmsCargo.setUpdateBy(getUsername());
        return toAjax(wmsCargoService.updateWmsCargo(wmsCargo));
    }

    /**
     * 删除货物信息
     */
    @Log(title = "货物信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsCargoService.deleteWmsCargoByIds(ids));
    }

    @PostMapping("checkSn")
    public AjaxResult checkSn(@RequestBody WmsCargo wmsCargo)
    {
        return AjaxResult.success(wmsCargoService.checkSn(wmsCargo));
    }
}
